#pragma once
#include "../data/TreasuryFuturesData.h"
#include <QWidget>
#include <QStylePainter>
#include <vector>
#include <string>
#include <tfbondlib/tfCTDInfo.h>

class SVirtualTable;
class DefaultTableModel;
class STableColumnSet;
class CFixedNatFutureData;

class TreasuryFuturesList : public QWidget
{
	Q_OBJECT
public:
	TreasuryFuturesList(QWidget* p, CFixedNatFutureData* data);
	enum emCol {
		fuCol_TF = 0,		//合约
		fuCol_Prc,			//最新价(元)
		fuCol_Chg,			//涨跌(元)
		fuCol_Rate,			//隐含利率(%)info
		fuCol_BP,			//BP
		fuCol_Vol,			//成交量(手)
		fuCol_Hold,			//持仓量(手)
		fuCol_CTD,			//CTD
		fuCol_CTD_Trading,	//CTD成交(%)
		fuCol_Basis,		//基差(元)
		fuCol_Max
	};
	void onRefresh();

protected slots:
	void onListRowClicked(const QModelIndex& index);

signals:
	void clickedRow(const QString& TFId);

private:
	void initTable();
	void updateTable(bool reset);
	void getCTDRateBP(const CFixedNatFutureTFData& tfPrice, const CCTDGetInfo& ctd, 
		QString& strCTD, QString& strRate, QString& strBP, QColor& crFgClr, std::string& bondkey);
	double getBondDealYield(const MarketStreamInfo& mtk) const;
	double getBondDealPrice(const MarketStreamInfo& mtk) const;
	bool verifyValidCalculate(double data, bool bNeedZero);

private:
	SVirtualTable* m_table;
	STableColumnSet* m_tableSet;
	DefaultTableModel* m_model;
	std::vector<emCol> m_cols;
	CFixedNatFutureData* m_data;
};